﻿@{
    ViewBag.Title = "DictionaryCheck";
}
@model string
@section head
{
    <link href="@Url.Content("~/ScriptPlugin/easyui/themes/gray/easyui.css")" rel="stylesheet" />
    <link href="@Url.Content("~/ScriptPlugin/easyui/themes/icon.css")" rel="stylesheet" />
    <script type="text/javascript" src="@Url.Content("~/ScriptPlugin/easyui/jquery.easyui.min.js")"></script>
    <script type="text/javascript" src="@Url.Content("~/ScriptPlugin/easyui/locale/easyui-lang-zh_CN.js")"></script>
    <script type="text/javascript" src="@Url.Content("~/Scripts/KingsSharp.DataGrid.Filter.js")"></script>
    <script src="@Url.Content("~/ScriptPlugin/WdatePicker/js/WdatePicker.js")"></script>
    <script src="@Url.Content("~/Scripts/jquery.linq.min.js")"></script>
<script src="@Url.Content("~/ScriptPlugin/ztree/js/jquery.ztree.core-3.5.js")" type="text/javascript"></script>
<link href="@Url.Content("~/ScriptPlugin/ztree/css/zTreeStyle/zTreeStyle.css")" rel="stylesheet" type="text/css" />
}
<div style="float: left; width: 190px; height: 100%">
    <div style="padding-top: 1px">
        <ul id="tree" class="ztree"></ul>
    </div>
</div>
<div style="position:absolute;left:190px;right:0;height:100%">
    <div id="grid">
        <div id="toolpannel">
            <div class="content-pannel-buttons">
                <a onclick="$('#grid').datagrid('load')">
                    <b class="p-icon-serch">查询</b>
                </a>
            </div>
            <div class="datagrid-filter-pannel" id="filterpannel">
                <table class="content-table-serch">
                    <tr>
                        <th>
                            钢材品种名称
                            <input type="hidden" data-filter="true" id="Type" name="Type" />
                            <input type="hidden" data-filter="true" id="Parent.Id" name="Parent.Id" />
                        </th>
                        <td>
                            <input type="text" name="Name" data-filter="true" />
                            <a class="p-icon-filter p-icon-filter-style" style="display: block; width: 22px;
                                        height: 22px; float: left">@Html.GetFilterItem("Name", typeof(string))</a>
                                    </td>
                                    <th>
                                      
                                    </th>
                                    <td>
                                       
                                    </td>
                                    <th>

                                    </th>
                                    <td></td>
                                </tr>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
@section foot{
    <script type="text/javascript">
        var jsonTree = @MvcHtmlString.Create(Model);
        var settings = { callback: { onClick: nodeClick } };
        var zTree = $.fn.zTree.init($("#tree"), settings, jsonTree);
        if (jsonTree && jsonTree.length > 0) {
            $("#Parent\\.Id").val(jsonTree[0].id);
        }
        function nodeClick(e,treeId, treeNode)
        {
            $("#Parent\\.Id").val(treeNode.id);
            $("#grid").datagrid("load");
        }


        var single=@ViewBag.Multi;
        function LoadDictionaryInfoData() {
            var columns = [[
                { field: "ck", checkbox: true},
                { field: "Name", title: "钢材名称", width: 180},
                { field: "Description", title: "钢材说明", width: 400},
                { field: "DictionaryTypeName", title: "钢材类别"}
            ]];
            var parameter = {
                title: null,
                columns: columns,
                url: "@Url.Content("~/Sys/Dictionary/GetDictionaryGridData")",
                pageNumber: 1,
                singleSelect:!single,
                ctrlSelect:!single,
                onCheck: checkRow,
                onUncheck: uncheckRow,
                onCheckAll: checkAllRow,
                onUncheckAll: uncheckAllRow,
                onLoadSuccess:loadSuccess
            };
            var grid = K.GetGridData("#grid", parameter).Grid;
        }
        LoadDictionaryInfoData();
        var checkedRows = new Array();
        function loadSuccess()
        {
            var rows = $("#grid").datagrid("getRows");
            $.Enumerable.From(rows).ForEach(function (row,i) {
                if ($.Enumerable.From(checkedRows).Where(function (x) { return x.Id == row.Id; }).Count() != 0) {
                    $("#grid").datagrid("checkRow", i);
                }
            });
        }
        function checkRow(rows,rowData)
        {
            if ($.Enumerable.From(checkedRows).Where(function (x) { return x.Id == rowData.Id; }).Count() == 0)
            {
                checkedRows = $.Enumerable.From(checkedRows).Union([rowData]).ToArray();
            }
        }
        function uncheckRow(rows, rowData)
        {
            if ($.Enumerable.From(checkedRows).Where(function (x) { return x.Id == rowData.Id; }).Count() > 0) {
                checkedRows = $.Enumerable.From(checkedRows).Except([rowData]).ToArray();
            }
        }
        function checkAllRow(rows)
        {
            checkedRows = $.Enumerable.From(checkedRows).Union(rows).ToArray();
        }
        function uncheckAllRow(rows)
        {
            checkedRows = $.Enumerable.From(checkedRows).Except(rows).ToArray();
        }
        function SaveData(index)
        {
            parent.K.layer.callback(index, checkedRows);
            parent.K.layer.close(index);
        }
    </script>
}